1//////////////////////////////////////////////////////////////////////
  2// LibFile: constants.scad
  3//   Constants for directions (used with anchoring), and for specifying line termination for
  4//   use with geometry.scad.  
  5// Includes:
  6//   include <BOSL2/std.scad>
  7// FileGroup: Basic Modeling
  8// FileSummary: Constants provided by the library
  9// FileFootnotes: STD=Included in std.scad
 10//////////////////////////////////////////////////////////////////////
 11
 12// a value that the user should never enter randomly;
 13// result of `dd if=/dev/random bs=32 count=1 |base64` :
 14_UNDEF="LRG+HX7dy89RyHvDlAKvb9Y04OTuaikpx205CTh8BSI";
 15
 16// Section: General Constants
 17
 18// Constant: $slop
 19// Synopsis: The slop amount to make printed items fit closely. `0.0` by default.
 20// Topics: Constants
 21// Description:
 22//   A number of printers, particularly FDM/FFF printers, tend to be a bit sloppy in their printing.
 23//   This has made it so that some parts won't fit together without adding a bit of extra slop space.
 24//   That is what the `$slop` value is for.  The value for this will vary from printer to printer.
 25//   By default, we use a value of 0.00 so that parts should fit exactly for resin and other precision
 26//   printers.  This value is measured in millimeters.  When making your own parts, you should add
 27//   `$slop` to both sides of a hole that another part is to fit snugly into. For a loose fit, add
 28//   `2*$slop` to each side.  This should be done for both X and Y axes.  The Z axis will require a
 29//   slop that depends on your layer height and bridging settings, and hole sizes.  We leave that as
 30//   a more complicated exercise for the user.
 31//   .
 32//   Note that the slop value is accessed using the {{get_slop()}} function.  This function provides
 33//   the default value of 0 if you have not set `$slop`. This approach makes it possible for you to
 34//   set `$slop` in your programs without experiencing peculiar OpenSCAD issues having to do with multiple
 35//   definitions of the variable.  If you write code that uses `$slop` be sure to reference it using {{get_slop()}}. 
 36// DefineHeader(NumList): Calibration
 37// Calibration: To calibrate the `$slop` value for your printer, follow this procedure:
 38//   Print the Slop Calibration part from the example below.
 39//   Take the long block and orient it so the numbers are upright, facing you.
 40//   Take the plug and orient it so that the arrow points down, facing you.
 41//   Starting with the hole with the largest number in front of it, insert the small end of the plug into the hole.
 42//   If you can insert and remove the small end of the plug from the hole without much force, then try again with the hole with the next smaller number.
 43//   Repeat step 5 until you have found the hole with the smallest number that the plug fits into without much force.
 44//   The correct hole should hold the plug when the long block is turned upside-down.
 45//   The number in front of that hole will indicate the `$slop` value that is ideal for your printer.
 46//   Remember to set that slop value in your scripts after you include the BOSL2 library:  ie: `$slop = 0.15;`
 47// Example(3D,Med): Slop Calibration Part.
 48//   min_slop = 0.00;
 49//   slop_step = 0.05;
 50//   holes = 8;
 51//   holesize = [15,15,15];
 52//   height = 20;
 53//   gap = 5;
 54//   l = holes * (holesize.x + gap) + gap;
 55//   w = holesize.y + 2*gap;
 56//   h = holesize.z + 5;
 57//   diff("holes")
 58//   cuboid([l, w, h], anchor=BOT) {
 59//     for (i=[0:holes-1]) {
 60//       right((i-holes/2+0.5)*(holesize.x+gap)) {
 61//         s = min_slop + slop_step * i;
 62//         tag("holes") {
 63//           cuboid([holesize.x + 2*s, holesize.y + 2*s, h+0.2]);
 64//           fwd(w/2-1) xrot(90) linear_extrude(1.1) {
 65//             text(
 66//               text=format_fixed(s,2),
 67//               size=0.4*holesize.x,
 68//               halign="center",
 69//               valign="center"
 70//             );
 71//           }
 72//         }
 73//       }
 74//     }
 75//   }
 76//   back(holesize.y*2.5) {
 77//     difference() {
 78//       union() {
 79//         cuboid([holesize.x+10, holesize.y+10, 15], anchor=BOT);
 80//         cuboid([holesize.x, holesize.y, 15+holesize.z], anchor=BOT);
 81//       }
 82//       up(3) fwd((holesize.y+10)/2) {
 83//         prismoid([holesize.x/2,1], [0,1], h=holesize.y-6);
 84//       }
 85//     }
 86//   }
 87// Example(2D): Where to add `$slop` gaps.
 88//   $slop = 0.2;
 89//   difference() {
 90//     square([20,12],center=true);
 91//     back(3) square([10+2*$slop,11],center=true);
 92//   }
 93//   back(8) {
 94//     rect([15,5],anchor=FWD);
 95//     rect([10,8],anchor=BACK);
 96//   }
 97//   color("#000") {
 98//     arrow_path = [[5.1,6.1], [6.0,7.1], [8,7.1], [10.5,10]];
 99//     xflip_copy()
100//       stroke(arrow_path, width=0.3, endcap1="arrow2");
101//     xcopies(21) back(10.5) {
102//         back(1.8) text("$slop", size=1.5, halign="center");
103//         text("gap", size=1.5, halign="center");
104//     }
105//   }
106
107// Function: get_slop()
108// Synopsis: Returns the $slop value.
109// Topics: Slop
110// See Also: $slop
111// Usage:
112//    slop = get_slop();
113// Description:
114//    Returns the current $slop value, or the default value if the user did not set $slop.
115//    Always acess the `$slop` variable using this function.  
116function get_slop() = is_undef($slop) ? 0 : $slop;
117
118
119// Constant: INCH
120// Synopsis: A constant containing the  number of millimeters in an inch. `25.4`
121// Topics: Constants
122// Description:
123//   The number of millimeters in an inch.
124// Example(2D):
125//   square(2*INCH, center=true);
126// Example(3D):
127//   cube([4,3,2.5]*INCH, center=true);
128INCH = 25.4;
129
130
131// Constant: IDENT
132// Synopsis: A constant containing the 3D identity transformation matrix.
133// SynTags: Mat
134// Topics: Constants, Affine, Matrices, Transforms
135// See Also: ident()
136// Description: Identity transformation matrix for three-dimensional transforms.  Equal to `ident(4)`.  
137IDENT=ident(4);
138
139
140
141// Section: Directional Vectors
142//   Vectors useful for `rotate()`, `mirror()`, and `anchor` arguments for `cuboid()`, `cyl()`, etc.
143
144// Constant: LEFT
145// Synopsis: The left-wards (X-) direction vector constant `[-1,0,0]`.
146// Topics: Constants, Vectors
147// See Also: RIGHT, FRONT, BACK, UP, DOWN, CENTER
148// Description: Vector pointing left.  [-1,0,0]
149// Example(3D): Usage with `anchor`
150//   cuboid(20, anchor=LEFT);
151LEFT  = [-1,  0,  0];
152
153// Constant: RIGHT
154// Synopsis: The right-wards (X+) direction vector constant `[1,0,0]`.
155// Topics: Constants, Vectors
156// See Also: LEFT, FRONT, BACK, UP, DOWN, CENTER
157// Description: Vector pointing right.  [1,0,0]
158// Example(3D): Usage with `anchor`
159//   cuboid(20, anchor=RIGHT);
160RIGHT = [ 1,  0,  0];
161
162// Constant: FRONT
163// Aliases: FWD, FORWARD
164// Synopsis: The front-wards (Y-) direction vector constant `[0,-1,0]`.
165// Topics: Constants, Vectors
166// See Also: LEFT, RIGHT, BACK, UP, DOWN, CENTER
167// Description: Vector pointing forward.  [0,-1,0]
168// Example(3D): Usage with `anchor`
169//   cuboid(20, anchor=FRONT);
170FRONT = [ 0, -1,  0];
171FWD = FRONT;
172FORWARD = FRONT;
173
174// Constant: BACK
175// Synopsis: The backwards (Y+) direction vector constant `[0,1,0]`.
176// Topics: Constants, Vectors
177// See Also: LEFT, RIGHT, FRONT, UP, DOWN, CENTER
178// Description: Vector pointing back.  [0,1,0]
179// Example(3D): Usage with `anchor`
180//   cuboid(20, anchor=BACK);
181BACK  = [ 0,  1,  0];
182
183// Constant: BOTTOM
184// Aliases: BOT, DOWN
185// Synopsis: The down-wards (Z-) direction vector constant `[0,0,-1]`.
186// Topics: Constants, Vectors
187// See Also: LEFT, RIGHT, FRONT, BACK, UP, CENTER
188// Description: Vector pointing down.  [0,0,-1]
189// Example(3D): Usage with `anchor`
190//   cuboid(20, anchor=BOTTOM);
191BOTTOM  = [ 0,  0, -1];
192BOT = BOTTOM;
193DOWN = BOTTOM;
194
195// Constant: TOP
196// Aliases: UP
197// Synopsis: The top-wards (Z+) direction vector constant `[0,0,1]`.
198// Topics: Constants, Vectors
199// See Also: LEFT, RIGHT, FRONT, BACK, DOWN, CENTER
200// Description: Vector pointing up.  [0,0,1]
201// Example(3D): Usage with `anchor`
202//   cuboid(20, anchor=TOP);
203TOP = [ 0,  0,  1];
204UP = TOP;
205
206// Constant: CENTER
207// Aliases: CTR, CENTRE
208// Synopsis: The center vector constant `[0,0,0]`.
209// Topics: Constants, Vectors
210// See Also: LEFT, RIGHT, FRONT, BACK, UP, DOWN
211// Description: Zero vector.  Centered.  [0,0,0]
212// Example(3D): Usage with `anchor`
213//   cuboid(20, anchor=CENTER);
214CENTER = [ 0,  0,  0];  // Centered zero vector.
215CTR = CENTER;
216CENTRE = CENTER;
217
218
219// Section: Line specifiers
220//   Used by functions in geometry.scad for specifying whether two points
221//   are treated as an unbounded line, a ray with one endpoint, or a segment
222//   with two endpoints.  
223
224// Constant: SEGMENT
225// Synopsis: A constant for specifying a line segment in various geometry.scad functions.  `[true,true]`
226// Topics: Constants, Lines
227// See Also: RAY, LINE
228// Description: Treat a line as a segment.  [true, true]
229// Example: Usage with line_intersection:
230//    line1 = 10*[[9, 4], [5, 7]];
231//    line2 = 10*[[2, 3], [6, 5]];
232//    isect = line_intersection(line1, line2, SEGMENT, SEGMENT);
233SEGMENT = [true,true];
234
235
236// Constant: RAY
237// Synopsis: A constant for specifying a ray line in various geometry.scad functions.  `[true,false]`
238// Topics: Constants, Lines
239// See Also: SEGMENT, LINE
240// Description: Treat a line as a ray, based at the first point.  [true, false]
241// Example: Usage with line_intersection:
242//    line = [[-30,0],[30,30]];
243//    pt = [40,25];
244//    closest = line_closest_point(line,pt,RAY);
245RAY = [true, false];
246
247
248// Constant: LINE
249// Synopsis: A constant for specifying an unbounded line in various geometry.scad functions.  `[false,false]`
250// Topics: Constants, Lines
251// See Also: RAY, SEGMENT
252// Description: Treat a line as an unbounded line.  [false, false]
253// Example: Usage with line_intersection:
254//    line1 = 10*[[9, 4], [5, 7]];
255//    line2 = 10*[[2, 3], [6, 5]];
256//    isect = line_intersection(line1, line2, LINE, SEGMENT);
257LINE = [false, false];
258
259
260// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap